


class UI:
	
	def __init__(self, empty, camera, text, add, mover, keyboard):
		self.camera = camera
		self.add = add  #add object actuator on empty
		self.mover = mover
		self.empty = empty
		self.keyboard = keyboard
		#set the position of the empty
		self.schemes = {"default": [30, 0, 20, 60], "exotic": [25, 0, 20, 60] }
		#define color schemes
		
		
	def addColorScheme(self, name, textColor, buttonbg, buttont, buttonroll):
		self.schemes[name] = [textColor, buttonbg, buttont, buttonroll]

	def addColum(self, x, y, entries, scheme):
		self.add.setObject("text")
		i = 0
		objects = []
		for entry in entries:
			print self.empty.getPosition()
			self.empty.setPosition( (x, y - (i*.15), 0 ))
			
			i += 1
			self.add.instantAddObject()
			last = self.add.getLastCreatedObject()
			last.Text = entry
			last.color = self.schemes[scheme][0]
			objects.append( last )
		return colum(objects)
			
	def addButton(self, name, x, y, scheme):
		self.add.setObject("button.001")
		self.empty.setPosition( (x, y, 0) )
		self.add.instantAddObject()
		last = self.add.getLastCreatedObject()
		last.Text = name
		last.children[0].color = self.schemes[scheme][1]
		last.color = self.schemes[scheme][2]
		last.roll = self.schemes[scheme][3]
		
		
		last.children[0].scaling = ( (len(name)  )*.5 + 2, 1, 1)
		return button(last)
	
	def addBList(self, entries, x, y, scheme):
		#return a list of button objects
		i = 0
		objects = []
		for entry in entries:
			objects.append( self.addButton( entry, x, y - (i*.25), scheme) )
			i += 1
		return blist(objects, self.mover, self.keyboard)
	
	
			
	def addInputText(self, length, x, y, scheme):
		self.add.setObject("button")
		self.empty.setPosition( (x, y, 0) )
		self.add.instantAddObject()
		last = self.add.getLastCreatedObject()
		last.Text = ""
		last.children[0].color = self.schemes[scheme][1]
		last.color = self.schemes[scheme][2]
		last.roll = self.schemes[scheme][3]
		
		
		last.children[0].scaling = ( (len(name)  )*.5 + 2, 1, 1)
		return button(last)
 
	def addSlider(self):
		pass
	
	def addRadioButton(self):
		pass
	
### UI element classes

class button:
	
	def __init__(self, object):
		
		self.text = object
		self.object = object.children[0]
		
	def delete(self):
		self.text.endObject()
		
	def disable(self):
		pass
		#change color scheme and mark disabled
	
	def enable(self):
		pass
		#change color scheme and mark enabled
		
class colum:
	
	
	def __init__(self, list):
		
		self.list = list
		
	def delete(self):
		for entry in self.list:
			entry.endObject()
			
class blist:
	
	def __init__(self, list, mover, keyboard):
		self.list = list
		self.mover = mover
		self.keyboard = keyboard
		self.selected = 0
		self.update()
		
	
	def update(self):
		for entry in self.list:
			entry.object.visible = 0
		self.list[self.selected].object.visible = 1
		
	def check(self):
		i = 0
		for entry in self.list:
			if self.mover.getHitObject() == entry.object:
				self.selected = i
				self.update()
			i += 1
	def keys(self, cpk):
		for entry in cpk:
			if entry[1] == 1:
				if entry[0] == 146:
					if self.selected == 0:
						self.selected = len(self.list)-1
					#elif self.selected = len(list)-1:
					#	self.selected = 0
					else:
						self.selected -= 1
					self.update()
				if entry[0] == 144:
					if self.selected == len(self.list)-1:
						self.selected = 0
					#elif self.selected = len(list)-1:
					#	self.selected = 0
					else:
						self.selected += 1
					self.update()

class inputText:
	
	def __init__(self, object):
		pass
	
	def event(self):
		pass
			